Overview
This standalone script fetches all NSE stocks with F&O (Futures & Options) availability from the ScanX API. It’s not part of the main pipeline because F&O data is relatively static and doesn’t need daily updates.Why Standalone?
- Infrequent Updates: F&O stock list changes rarely (only when new stocks are added/removed from F&O segment)
- One-Time Fetch: Typically run once to get the initial list, then occasionally to update
- Independent Data: Doesn’t integrate with other pipeline outputs
- Manual Trigger: Should be run manually when you need to refresh the F&O stock universe
What It Fetches
The script retrieves comprehensive fundamental and technical data for all F&O-enabled stocks:Fundamental Fields
- Market Cap, P/E Ratio, Dividend Yield
- Revenue, Revenue Growth (1 Year)
- Net Profit Margin, EBITDA Margin
- EPS, ROE, ROCE
- Price-to-Book (P/B) Ratio
Technical Fields
- OHLC (Open, High, Low, Last Traded Price)
- Moving Averages (SMA 50, SMA 200)
- RSI (14-day)
- Price changes (1 week, 1 month, 1 year, 3 year, 5 year)
- 52-week highs/lows and distance from them
- Bollinger Bands, ATR
Output Files
Contains array of F&O stock objects with all fetched fields. Saved in the current working directory.
API Reference
fetch_fno_flag_data()
Fetches all F&O stocks from the ScanX API.
This function takes no parameters.
None (outputs to file)
API Endpoint:
- Catches and prints any request exceptions
- Validates response structure before saving
- Uses
raise_for_status()to catch HTTP errors
When to Run Manually
Initial Setup
Initial Setup
Run once when setting up the pipeline to get the complete F&O stock universe.
Quarterly Review
Quarterly Review
Check after NSE announces new F&O stock additions (typically quarterly).
Missing Stocks
Missing Stocks
If you notice a known F&O stock missing from your data.
Usage
Source Code
Dependencies
requests: HTTP library for API callsjson: JSON serialization/deserializationtime: (imported but not used in current version)
This script uses hardcoded headers and does not import from
pipeline_utils.py. If you need user-agent rotation, consider refactoring to use get_headers().